require("./css/index.scss");
require("../common/common.scss");

import {
    createBtnHandler
} from './create';
import {
    editBtnHandler
} from './edit';
import {
    removeBtnHandler
} from './remove';

import {
    grid
} from '../common/grid';
import {
    editPwd,
    loginOut
} from '../common/settings';
$(function () {
    grid();
    window.editPwd = editPwd;
    window.loginOut = loginOut;

    let $table = $('#table').bootstrapTable({
        toolbar: '#toolbar',
        url: GLOBAL_ListUrl,

        sidePagination: "server",
        detailView: true,
        detailFormatter: function (index, row, element) {
            let markup = `<ul class="tag-box"> 
                             <li>清理区域：${row.area}</li>                     
                          </ul>`;
            return markup;
        },
        queryParamsType: '',
        columns: [{
            checkbox: true
        }, {
            field: 'name',
            title: '部门名称',
            sortable: true
        }, {
            field: 'add_uname',
            title: '创建者',
            sortable: true,

        }, {
            field: 'is_copy',
            title: '是否抄送',
            sortable: true,
            formatter: function (value, row, index) {
                return parseInt(value) == 1 ? "是" : "否";
            }
        }, {
            field: 'send_name',
            title: '抄送人姓名',
            sortable: true,
            formatter: function (value, row, index) {
                return value===''? "抄送人姓名为空" : value;
            }
        }, {
            field: 'copy_name',
            title: '抄送人邮箱',
            sortable: true,
            formatter: function (value, row, index) {
                return value===''? "抄送人邮件为空" : value;
            }
        }, {
            field: 'operate',
            title: '操作',
            formatter: function (value, row, index) {
                return`<a class="btn btn-primary btn-sm" href="${GLOBAL_staffUrl}?secid=${row.id}" title="查看员工">查看员工</a>`;
            }
        }]
    });

    //多选不能编辑,删除
    $table.on('check.bs.table', () => {
        let selectedList = $('#table').bootstrapTable('getSelections');
        if (selectedList.length > 1) {
            $('#editBtn').attr('disabled', 'disabled');
            return;
        }
        $('#editBtn').removeAttr('disabled');
    });

    $table.on('uncheck.bs.table', () => {
        let selectedList = $('#table').bootstrapTable('getSelections');
        if (selectedList.length > 1) {
            $('#editBtn').attr('disabled', 'disabled');
            $('#removeBtn').attr('disabled', 'disabled');
            return;
        }
        $('#editBtn').removeAttr('disabled');
        $('#removeBtn').removeAttr('disabled');
    });
    $table.on('check-all.bs.table', (rows) => {
        $('#editBtn').attr('disabled', 'disabled');
        $('#removeBtn').attr('disabled', 'disabled');
    });
    $table.on('uncheck-all.bs.table', (rows) => {
        $('#editBtn').removeAttr('disabled');
        $('#removeBtn').removeAttr('disabled');
    });

    window.createBtnHandler = createBtnHandler;
    window.editBtnHandler = editBtnHandler;
    window.removeBtnHandler = removeBtnHandler;

}());